package com.hn658.user.common.utils;

/**
 * Created by baihai on 2015/8/24.
 */
public class RedisKeyHelper {

    private static final String keyPrefix = "base:user:";
	
    /**
	 * 获取对应userId的后台用户信息key
	 * 
	 * @param userId
	 * @return
	 */
	public static String userId(String userId) {
		return keyPrefix+"uid:" + userId + ":userInfo";
	}
	
	/**
	 * 获取对应后台帐号的userId
	 * 
	 * @param userLoginAccount
	 * @return
	 */
	public static String userAccount(String userLoginAccount) {
		return keyPrefix+"userLoginAccount:" + userLoginAccount + ":userId";
	}
	
	/**
	 * 获取userId对应的auth
	 * 
	 * @param userId
	 * @return
	 */
	public static String userAuth(String userId) {
		return keyPrefix+"userId:" + userId + ":auth";
	}
	
	/**
	 * 获取userAuthKey对应的userId
	 * 
	 * @param userAuthKey
	 * @return
	 */
	public static String userAuthKey(String userAuthKey) {
		return keyPrefix+"auth:" + userAuthKey + ":userId";
	}
	
	/**
	 * 获取accountId对应的auth
	 * 
	 * @param accountId
	 * @return
	 */
	public static String accountAuth(String accountId) {
		return keyPrefix+"accountId:" + accountId + ":auth";
	}

    /**
     * 生成APPID的序列号
     * @return
     */
    public static String appIdSequence() {
        return keyPrefix+"appInfo:appId:sequence";
    }

    /**
     * 根据appId Key
     * @param appId
     * @return
     */
    public static String appId(String appId) {
        return keyPrefix+"appInfo:appId:"+appId;
    }
    
    /**
     * 根据app id
     * @param id
     * @return
     */
    public static String appInfoId(String id) {
        return keyPrefix+"appInfo:id:"+id+":Info";
    }

    /**
     * 数据字典生成key值， 由传入的type动态生成
     * @param type
     * @return
     */
    public static String dictionaryKey(String type){
        return keyPrefix+"dictionary:"+type+"type";
    }
    
    /**
	 * 获取对应uid的用户信息key
	 * @param uid
	 * @return
	 */
	public static String uid(String uid) {
		return keyPrefix+"uid:" + uid + ":userInfo";
	}
	
	/**
	 * 获取对应帐号的uid
	 * @param loginAccount
	 * @return
	 */
	public static String account(String loginAccount){
		return keyPrefix+"loginAccount:" + loginAccount + ":uid";
	}
	
	/**
	 * 获取uid对应的auth
	 * @param uid
	 * @return
	 */
	public static String auth(String uid){
		return keyPrefix+"uid:" + uid + ":auth";
	}
	
	/**
	 * 获取authkey对应的用户id
	 * @param authkey
	 * @return
	 */
	public static String authkey(String authkey){
		return keyPrefix+"auth:" + authkey + ":uid";
	}
	
	/**
	 * 根据tokenId获取账户信息
	 * @return
	 */
	public static String tokenAccount(String tokenId){
		return keyPrefix+"tokenId:" + tokenId + ":loginAccount";
	}

	/**
	 * 
	 * <p>权限信息ID缓存KEY</p> 
	 * @author ztjie
	 * @date 2015-11-5 下午3:46:38
	 * @param id
	 * @return
	 * @see
	 */
	public static String functionId(String id) {
		return keyPrefix+"function:id"+id+":info";
	}
	
	/**
	 * 
	 * <p>查询所有权限树信息</p> 
	 * @author ztjie
	 * @date 2015-11-5 下午3:46:38
	 * @param id
	 * @return
	 * @see
	 */
	public static String allTreeNode() {
		return keyPrefix+"function:allTreeNode";
	}

	/**
	 * 
	 * <p>权限信息uri缓存</p> 
	 * @author ztjie
	 * @date 2015-11-5 下午3:47:44
	 * @param uri
	 * @return
	 * @see
	 */
	public static String functionUri(String uri) {
		return keyPrefix+"function:functionUri:"+uri;
	}

	public static String userAccessTreeNodes(Long uid) {
		return keyPrefix+"user:treeNode:"+uid;
	}

	public static String userAccessUris(Long uid) {
		return keyPrefix+"user:accessUris:"+uid;
	}

	public static String userAccessIds(Long uid) {
		return keyPrefix+"user:accessIds:"+uid;
	}

	public static String userAccessPageElements(Long uid) {
		return keyPrefix+"user:userAccessPageElements:"+uid;
	}
	
	public static String userAccessAppKeys(String uid) {
		return keyPrefix+"user:userAccessAppKeys:"+uid;
	}
	
	public static String userAccessAppUris(String uid) {
		return keyPrefix+"user:userAccessAppUris:"+uid;
	}
}
